package com.bytedance.common.a;

import android.os.Handler;
import android.os.Looper;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

final class a {
    String a;
    List b;
    private String[] c;
    private long d;
    private long e;
    private Handler f;

    a(String arg5, long arg6, boolean arg8) {

        this.f = new b(this, Looper.getMainLooper());
        this.a = arg5;
        this.d = 300;
        this.e = System.currentTimeMillis() / 1000;
        this.a(arg8);
    }

    a(String arg7, boolean arg8) {

        this.f = new b(this, Looper.getMainLooper());
        try {
            JSONObject v1 = new JSONObject(arg7);
            this.a = v1.getString("host");
            JSONArray v2 = v1.getJSONArray("ips");
            int v3 = v2.length();
            this.c = new String[v3];
            this.b = new ArrayList();
            int v0_1;
            for(v0_1 = 0; v0_1 < v3; ++v0_1) {
                String v4 = v2.getString(v0_1);
                this.c[v0_1] = v4;
                if(i.b(v4)) {
                    this.b.add(InetAddress.getByAddress(this.a, InetAddress.getByName(v4).getAddress()));
                }
            }

            this.d = v1.getLong("ttl");
            this.e = System.currentTimeMillis() / 1000;
            this.a(arg8);
        }
        catch(Exception v0) {
            HttpDns.a(v0);
        }
    }

    private void a(boolean arg7) {
        this.f.removeMessages(0);
        if(arg7) {
            this.f.sendEmptyMessageDelayed(0, this.d * 1000);
        }
    }

    final void a() {
        this.f.removeMessages(0);
    }

    final boolean b() {
        boolean v0 = this.e + this.d >= System.currentTimeMillis() / 1000 ? true : false;
        return v0;
    }

    public final String toString() {
        String v1 = "host: " + this.a + " ip cnt: " + this.c.length + " ttl: " + this.d;
        int v0;
        for(v0 = 0; v0 < this.c.length; ++v0) {
            v1 = v1 + "\n ip: " + this.c[v0];
        }

        return v1;
    }
}

